from pyscf import gto, scf
from mokit.lib.fch2py import fch2py

mol = gto.M()
#  12 atom(s)
mol.atom = '''
Cu          0.00000000        1.40000000        0.00000000
Cu          0.00000000       -1.40000000        0.00000000
O           0.00000000        0.00000000        1.15000000
O           0.00000000        0.00000000       -1.15000000
N           0.00000000        3.40000000        0.00000000
N           0.00000000       -3.40000000        0.00000000
H          -0.93969300        3.74202000        0.00000000
H           0.93969300       -3.74202000        0.00000000
H           0.46984600        3.74202000        0.81379800
H          -0.46984600       -3.74202000       -0.81379800
H           0.46984600        3.74202000       -0.81379800
H          -0.46984600       -3.74202000        0.81379800
'''

mol.basis = {
'Cu': gto.basis.parse('''
Cu    S 
    0.817600000E+01   -0.421025989E+00
    0.256800000E+01    0.738592381E+00
    0.958700000E+00    0.552569186E+00
Cu    S 
    0.817600000E+01    0.178766454E+00
    0.256800000E+01   -0.359227208E+00
    0.958700000E+00   -0.470482380E+00
    0.115300000E+00    0.108074072E+01
Cu    S 
    0.396000000E-01    0.100000000E+01
Cu    P 
    0.256300000E+02   -0.489173002E-01
    0.316600000E+01    0.627285402E+00
    0.102300000E+01    0.471618802E+00
Cu    P 
    0.860000000E-01    0.100000000E+01
Cu    P 
    0.240000000E-01    0.100000000E+01
Cu    D 
    0.413400000E+02    0.465424016E-01
    0.114200000E+02    0.222782408E+00
    0.383900000E+01    0.453905916E+00
    0.123000000E+01    0.531476918E+00
Cu    D 
    0.310200000E+00    0.100000000E+01
'''),
'Cu': gto.basis.parse('''
Cu    S 
    0.817600000E+01   -0.421025989E+00
    0.256800000E+01    0.738592381E+00
    0.958700000E+00    0.552569186E+00
Cu    S 
    0.817600000E+01    0.178766454E+00
    0.256800000E+01   -0.359227208E+00
    0.958700000E+00   -0.470482380E+00
    0.115300000E+00    0.108074072E+01
Cu    S 
    0.396000000E-01    0.100000000E+01
Cu    P 
    0.256300000E+02   -0.489173002E-01
    0.316600000E+01    0.627285402E+00
    0.102300000E+01    0.471618802E+00
Cu    P 
    0.860000000E-01    0.100000000E+01
Cu    P 
    0.240000000E-01    0.100000000E+01
Cu    D 
    0.413400000E+02    0.465424016E-01
    0.114200000E+02    0.222782408E+00
    0.383900000E+01    0.453905916E+00
    0.123000000E+01    0.531476918E+00
Cu    D 
    0.310200000E+00    0.100000000E+01
'''),
'O': gto.basis.parse('''
O     S 
    0.117200000E+05    0.709645947E-03
    0.175900000E+04    0.546727229E-02
    0.400800000E+03    0.278231186E-01
    0.113700000E+03    0.104747740E+00
    0.370300000E+02    0.282920846E+00
    0.132700000E+02    0.448495239E+00
    0.502500000E+01    0.270816885E+00
    0.101300000E+01    0.154502916E-01
O     S 
    0.117200000E+05   -0.314443412E-03
    0.175900000E+04   -0.248213768E-02
    0.400800000E+03   -0.123163554E-01
    0.113700000E+03   -0.505389173E-01
    0.370300000E+02   -0.139384903E+00
    0.132700000E+02   -0.325077495E+00
    0.502500000E+01   -0.229848308E+00
    0.101300000E+01    0.109537935E+01
O     S 
    0.302300000E+00    0.100000000E+01
O     P 
    0.177000000E+02    0.626791663E-01
    0.385400000E+01    0.333536566E+00
    0.104600000E+01    0.741239642E+00
O     P 
    0.275300000E+00    0.100000000E+01
O     D 
    0.118500000E+01    0.100000000E+01
'''),
'O': gto.basis.parse('''
O     S 
    0.117200000E+05    0.709645947E-03
    0.175900000E+04    0.546727229E-02
    0.400800000E+03    0.278231186E-01
    0.113700000E+03    0.104747740E+00
    0.370300000E+02    0.282920846E+00
    0.132700000E+02    0.448495239E+00
    0.502500000E+01    0.270816885E+00
    0.101300000E+01    0.154502916E-01
O     S 
    0.117200000E+05   -0.314443412E-03
    0.175900000E+04   -0.248213768E-02
    0.400800000E+03   -0.123163554E-01
    0.113700000E+03   -0.505389173E-01
    0.370300000E+02   -0.139384903E+00
    0.132700000E+02   -0.325077495E+00
    0.502500000E+01   -0.229848308E+00
    0.101300000E+01    0.109537935E+01
O     S 
    0.302300000E+00    0.100000000E+01
O     P 
    0.177000000E+02    0.626791663E-01
    0.385400000E+01    0.333536566E+00
    0.104600000E+01    0.741239642E+00
O     P 
    0.275300000E+00    0.100000000E+01
O     D 
    0.118500000E+01    0.100000000E+01
'''),
'N': gto.basis.parse('''
N     S 
    0.904600000E+04    0.699617413E-03
    0.135700000E+04    0.538605463E-02
    0.309300000E+03    0.273910212E-01
    0.877300000E+02    0.103150592E+00
    0.285600000E+02    0.278570663E+00
    0.102100000E+02    0.448294849E+00
    0.383800000E+01    0.278085928E+00
    0.746600000E+00    0.154315612E-01
N     S 
    0.904600000E+04   -0.304990096E-03
    0.135700000E+04   -0.240802638E-02
    0.309300000E+03   -0.119444487E-01
    0.877300000E+02   -0.489259929E-01
    0.285600000E+02   -0.134472725E+00
    0.102100000E+02   -0.315112578E+00
    0.383800000E+01   -0.242857833E+00
    0.746600000E+00    0.109438221E+01
N     S 
    0.224800000E+00    0.100000000E+01
N     P 
    0.135500000E+02    0.589056768E-01
    0.291700000E+01    0.320461107E+00
    0.797300000E+00    0.753042062E+00
N     P 
    0.218500000E+00    0.100000000E+01
N     D 
    0.817000000E+00    0.100000000E+01
'''),
'N': gto.basis.parse('''
N     S 
    0.904600000E+04    0.699617413E-03
    0.135700000E+04    0.538605463E-02
    0.309300000E+03    0.273910212E-01
    0.877300000E+02    0.103150592E+00
    0.285600000E+02    0.278570663E+00
    0.102100000E+02    0.448294849E+00
    0.383800000E+01    0.278085928E+00
    0.746600000E+00    0.154315612E-01
N     S 
    0.904600000E+04   -0.304990096E-03
    0.135700000E+04   -0.240802638E-02
    0.309300000E+03   -0.119444487E-01
    0.877300000E+02   -0.489259929E-01
    0.285600000E+02   -0.134472725E+00
    0.102100000E+02   -0.315112578E+00
    0.383800000E+01   -0.242857833E+00
    0.746600000E+00    0.109438221E+01
N     S 
    0.224800000E+00    0.100000000E+01
N     P 
    0.135500000E+02    0.589056768E-01
    0.291700000E+01    0.320461107E+00
    0.797300000E+00    0.753042062E+00
N     P 
    0.218500000E+00    0.100000000E+01
N     D 
    0.817000000E+00    0.100000000E+01
'''),
'H': gto.basis.parse('''
H     S 
    0.130100000E+02    0.334987264E-01
    0.196200000E+01    0.234800801E+00
    0.444600000E+00    0.813682958E+00
H     S 
    0.122000000E+00    0.100000000E+01
H     P 
    0.727000000E+00    0.100000000E+01
'''),
'H': gto.basis.parse('''
H     S 
    0.130100000E+02    0.334987264E-01
    0.196200000E+01    0.234800801E+00
    0.444600000E+00    0.813682958E+00
H     S 
    0.122000000E+00    0.100000000E+01
H     P 
    0.727000000E+00    0.100000000E+01
'''),
'H': gto.basis.parse('''
H     S 
    0.130100000E+02    0.334987264E-01
    0.196200000E+01    0.234800801E+00
    0.444600000E+00    0.813682958E+00
H     S 
    0.122000000E+00    0.100000000E+01
H     P 
    0.727000000E+00    0.100000000E+01
'''),
'H': gto.basis.parse('''
H     S 
    0.130100000E+02    0.334987264E-01
    0.196200000E+01    0.234800801E+00
    0.444600000E+00    0.813682958E+00
H     S 
    0.122000000E+00    0.100000000E+01
H     P 
    0.727000000E+00    0.100000000E+01
'''),
'H': gto.basis.parse('''
H     S 
    0.130100000E+02    0.334987264E-01
    0.196200000E+01    0.234800801E+00
    0.444600000E+00    0.813682958E+00
H     S 
    0.122000000E+00    0.100000000E+01
H     P 
    0.727000000E+00    0.100000000E+01
'''),
'H': gto.basis.parse('''
H     S 
    0.130100000E+02    0.334987264E-01
    0.196200000E+01    0.234800801E+00
    0.444600000E+00    0.813682958E+00
H     S 
    0.122000000E+00    0.100000000E+01
H     P 
    0.727000000E+00    0.100000000E+01
''')}

mol.ecp = {
'Cu': gto.basis.parse_ecp('''
Cu nelec  10
Cu ul
1    511.99517600      -10.00000000
2     93.28010740      -72.55482820
2     23.22066690      -12.74502310
Cu S
0    173.11808500        3.00000000
1    185.24198900       23.83518250
2     73.15178470      473.89304900
2     14.68841570      157.63458200
Cu P
0    100.71913700        5.00000000
1    130.83456600        6.49909360
2     53.86837200      351.46053900
2     14.09894690       85.50160360
'''),
'Cu': gto.basis.parse_ecp('''
Cu nelec  10
Cu ul
1    511.99517600      -10.00000000
2     93.28010740      -72.55482820
2     23.22066690      -12.74502310
Cu S
0    173.11808500        3.00000000
1    185.24198900       23.83518250
2     73.15178470      473.89304900
2     14.68841570      157.63458200
Cu P
0    100.71913700        5.00000000
1    130.83456600        6.49909360
2     53.86837200      351.46053900
2     14.09894690       85.50160360
''')}

# Remember to check the charge and spin
mol.charge = 2
mol.spin = 0
mol.verbose = 4
mol.cart = True
mol.build()

mf = scf.UHF(mol)
mf.max_cycle = 1
mf.kernel()

# read MOs from .fch(k) file
nbf = mf.mo_coeff[0].shape[0]
nif = mf.mo_coeff[0].shape[1]
S = mol.intor_symmetric('int1e_ovlp')
Sdiag = S.diagonal()
alpha_coeff = fch2py('02-bis_6D10F.fchk', nbf, nif, Sdiag, 'a')
beta_coeff  = fch2py('02-bis_6D10F.fchk', nbf, nif, Sdiag, 'b')
mf.mo_coeff = (alpha_coeff, beta_coeff)
# read done

dm = mf.make_rdm1()
mf.max_cycle = 5
mf.kernel(dm)

